<?php
/**
 * @Author: lianlianzan(13040@qq.com)
 * @Date:   2018-08-18 16:40:16
 * @Last Modified by:   lianlianzan
 * @Last Modified time: 2022-03-26 22:13:51
 */

namespace app\admin\controller;
use app\common\controller\AdminController;

class MerchantNode extends AdminController {

    protected function initialize(): void {
		parent::initialize();
		$this->saveAndGetConfigIdentify('', '商家功能节点', '', 'merchantNode');

		$this->merchantNodeDao = model('MerchantNode');
	}

	public function index() {
		//获取列表
		$map = $parameter = array();
		$count = $this->merchantNodeDao->countSearch($map);
		$Page = new \org\util\PageBootstrap($count, config('app.per_page'), $parameter);
		$pageShow = $Page->show();
		list($list) = $this->merchantNodeDao->search($map, $Page->getLimit());
		$this->assign('list', $list);

		return $this->fetch();
	}

	public function listorders() {
		$result = parent::listorders($this->merchantNodeDao);

		if ($result !== false) {
			$this->success('排序更新成功');
		} else {
			$this->error('排序更新失败');
		}
	}

	public function add() {
		$id = input('param.id', '', '', 'intval');

		if ($id) {
			//获取节点信息
			$info = $this->merchantNodeDao->getInfo($id);
			//print_r($info);
		} else {
			$info = array();
		}
		$this->assign('id', $id);
		$this->assign('info', $info);

		return $this->fetch();
	}

	public function doAdd() {
		$id = input('post.id', '', 'intval');
		$data = input('post.data/a', '', '', 'pwEscape');

		if ($id) {
			$info = $this->merchantNodeDao->getInfo($id);
		}

		if ($id) {
			$result = $this->merchantNodeDao->baseUpdateData($id, $data);
			if ($result !== false) {
				$this->success('保存成功', url('admin/merchantNode/index'));
			} else {
				$this->error('保存失败'.showDbError($this->merchantNodeDao));
			}
		} else {
			$result = $this->merchantNodeDao->baseAddData($data);
			if ($result !== false) {
				$this->success('添加成功', url('admin/merchantNode/index'));
			} else {
				$this->error('添加失败'.showDbError($this->merchantNodeDao));
			}
		}
	}

	public function doDelete() {
		$id = input('param.id', '', '', 'intval');

		if ($id) {
			$info = $this->merchantNodeDao->getInfo($id);
		}

		$result = $this->merchantNodeDao->del($id);
		if ($result !== false) {
			$this->success('删除成功', url('admin/merchantNode/index'));
		} else {
			$this->error('删除失败'.showDbError($this->merchantNodeDao));
		}
	}

}